package com.contain.auth.service;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @author suidd
 * @name UserDetailsEntity
 * @description 用户详情实体类
 * @date 2020/4/7 17:39
 * Version 1.0
 **/
@Data
public class UserDetailsEntity implements UserDetails {
    private static final long serialVersionUID = 8081363717997957932L;
    /**
     * 帐号
     */
    private String id;
    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;
    /**
     * 组织ID
     */
    private String orgId;
    /**
     * 组织名称
     */
    private String orgName;
    /**
     * 用户角色权限
     */
    private Collection<? extends GrantedAuthority> authorities;

    /**
     * 帐号是否过期
     */
    private boolean accountNonExpired = true;
    /**
     * 认证是否过期
     */
    private boolean credentialsNonExpired = true;
    /**
     * 帐号是否锁定
     */
    private boolean accountNonLocked = true;
    /**
     * 帐号是否删除
     */
    private boolean enabled = true;

    /**
     * 构造
     *
     * @param id
     * @param username
     * @param password
     * @param orgId
     * @param orgName
     * @param authorities
     */
    public UserDetailsEntity(String id, String username, String password, String orgId, String orgName, Collection<? extends GrantedAuthority> authorities) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.orgId = orgId;
        this.orgName = orgName;
        this.authorities = authorities;
    }

    /**
     * @param
     * @return change notes
     * @author suidd
     * @description //获取用户角色权限
     * @date 2020/4/10 13:55
     **/
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    /**
     * @param
     * @return change notes
     * @author suidd
     * @description //获取密码
     * @date 2020/4/10 13:56
     **/
    @Override
    public String getPassword() {
        return password;
    }

    /**
     * @param
     * @return change notes
     * @author suidd
     * @description //获取用户名
     * @date 2020/4/10 13:56
     **/
    @Override
    public String getUsername() {
        return username;
    }

    /**
     * @param
     * @return change notes
     * @author suidd
     * @description //帐号是否过期
     * @date 2020/4/10 13:52
     **/
    @Override
    public boolean isAccountNonExpired() {
        return this.accountNonExpired;
    }

    /**
     * @param
     * @return change notes
     * @author suidd
     * @description //帐号是否被锁定
     * @date 2020/4/10 13:53
     **/
    @Override
    public boolean isAccountNonLocked() {
        return this.accountNonLocked;
    }

    /**
     * @param
     * @return change notes
     * @author suidd
     * @description //认证是否过期
     * @date 2020/4/10 13:53
     **/
    @Override
    public boolean isCredentialsNonExpired() {
        return this.credentialsNonExpired;
    }

    /**
     * @param
     * @return change notes
     * @author suidd
     * @description //帐号是否被删除
     * @date 2020/4/10 13:53
     **/
    @Override
    public boolean isEnabled() {
        return this.enabled;
    }
}
